package com.caifu.controller;
import com.caifu.pojo.SysOrganization;
import com.caifu.pojo.SysUser;
import com.caifu.pojo.YlBasicData;
import com.caifu.pojo.YlPensionStatistic;
import com.caifu.service.IHealthArchiveService;
import com.caifu.service.IStatisticsDataService;
import com.caifu.service.SysOrganizationService;
import com.caifu.service.YlUserMedicineService;
import com.caifu.util.Constance;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/statistics")
public class StatisticsController extends AbstractController{


    @Autowired
    private IStatisticsDataService statisticsDataService;
    @Autowired
    private YlUserMedicineService medicineService;
    @Autowired
    private IHealthArchiveService healthArchiveService;
    @Autowired
    private SysOrganizationService orgService;

    /**
     *
     * 功能描述：养老机构统计首页
     *
     * @Author  GZ
     * @Date   2020/11/23 15:53
     */
    @RequestMapping("pensionOrgData")
    public String pensionOrgData(Model model){
        try {
            //查询总统计信息
            JSONObject allData = statisticsDataService.queryPensionBasicInfo();
            //查询核定床位统计信息
            YlBasicData basicData = statisticsDataService.queryBasicDataInfo();
            model.addAttribute("basicData",basicData);
            model.addAttribute("allData",allData);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "statistic/pensionOrgData";
    }



    /**
    * 
    * 功能描述：养老机构统计首页
    *
    * @Author  GZ
    * @Date   2020/11/23 15:53
    */
    @RequestMapping("pensionInstitutions")
    public String pensionInstitutions(Model model){
        SysUser user = getUser();
        try {
            String pensionNo = Constance.Null2EmptyTrim(user.getCurrentPensionNo());
            model.addAttribute("pensionNo",pensionNo);
            //查询消息信息
            JSONObject message = healthArchiveService
                    .queryAllHealthyNursingByPensionNo(user.getCurrentPensionNo());
            model.addAttribute("message",message);
            //查询养老机构信息
            SysOrganization org = orgService.getById(pensionNo);
            model.addAttribute("pensionName",org.getOrgName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "statistic/pensionInstitutions";
    }
    /**
    * 
    * 功能描述：获取床位统计数据
    *
    * @Author  GZ
    * @Date   2020/11/23 15:58
    */
    @RequestMapping("obtainBedStatisticData")
    @ResponseBody
    public JSONObject obtainBedStatisticData(String pensionNo){
        try {
            return statisticsDataService.queryBedStatisticInfo(pensionNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *
     * 功能描述：老人统计信息
     *
     * @Author  GZ
     * @Date   2020/11/23 15:58
     */
    @RequestMapping("obtainManStatisticData")
    @ResponseBody
    public JSONObject obtainManStatisticData(String pensionNo){
        try {
            return statisticsDataService.queryOldManBasicStatisticData(pensionNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
    * 
    * 功能描述：获取费用统计信息
    *
    * @Author  GZ
    * @Date   2020/11/27 13:11
    */
    @RequestMapping("obtainPensionFeeStatisticData")
    @ResponseBody
    public JSONObject obtainPensionFeeStatisticData(String pensionNo,String year,String month){
        try {
            return statisticsDataService
                    .queryBillStatisticDateInfo(pensionNo,year,month);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
    * 
    * 功能描述：按天获取缴费记录统计信息
    *
    * @Author  GZ
    * @Date   2020/11/27 14:21
    */
    @RequestMapping("obtainPaymentStatisticDataByDay")
    @ResponseBody
    public JSONObject obtainPaymentStatisticDataByDay(String pensionNo,String year,String month){
        try {
            return statisticsDataService.queryPaymentInfoByMonth(pensionNo,year,month);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *
     * 功能描述：按月份获取缴费记录统计信息
     *
     * @Author  GZ
     * @Date   2020/11/27 14:21
     */
    @RequestMapping("obtainPaymentStatisticDataByMonth")
    @ResponseBody
    public JSONObject obtainPaymentStatisticDataByMonth(String pensionNo,String year){
        try {
            return statisticsDataService.queryPaymentInfoByYear(pensionNo,year);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *
     * 功能描述：获取欠费人员信息列表
     *
     * @Author  GZ
     * @Date   2020/11/27 14:21
     */
    @RequestMapping("obtainOwningMoneyUserData")
    @ResponseBody
    public JSONObject obtainOwningMoneyUserData(String pensionNo,int maxSize){
        try {
            return statisticsDataService.queryOwingPayUserInfo(pensionNo,maxSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
    * 
    * 功能描述：查询老人生日信息列表
    * 
    * @Param
    * @Return      
    * @Exception   
    * @Author  GZ
    * @Date   2020/11/27 17:10
    */
    @RequestMapping("obtainBirthDayUserStatisticDataByMonth")
    @ResponseBody
    public JSONObject obtainBirthDayUserStatisticDataByMonth(String pensionNo){
        try {
            return statisticsDataService.queryBirthInfo(pensionNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
    * 
    * 功能描述：获取健康档案预警信息
    * 
    * @Param
    * @Return      
    * @Exception   
    * @Author  GZ
    * @Date   2020/11/29 11:56
    */
    @RequestMapping("obtainHealthyArchiveAlertData")
    @ResponseBody
    public JSONObject obtainHealthyArchiveAlertData(String pensionNo,int maxSize){
        try {
            return statisticsDataService.queryHealthyArchiveWarningData(pensionNo,maxSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
    * 
    * 功能描述：获取药物预警信息
    *
    * @Author  GZ
    * @Date   2020/11/29 13:08
    */
    @RequestMapping("obtainMedicineAlertData")
    @ResponseBody
    public JSONObject  obtainMedicineAlertData(String pensionNo,String type){
        try {
            return medicineService.queryAllMedicineAlertData(type,pensionNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *
     * 功能描述：获取护理评估提醒信息
     *
     * @Author  GZ
     * @Date   2020/11/29 13:08
     */
    @RequestMapping("obtainNursingAlertData")
    @ResponseBody
    public JSONObject  obtainNursingAlertData(String pensionNo,int maxSize){
        try {
            return statisticsDataService.queryUserNursingWarningDate(pensionNo,maxSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *
     * 功能描述：获取长护险提醒信息
     *
     * @Author  GZ
     * @Date   2020/11/29 13:08
     */
    @RequestMapping("obtainAssessmentAlertData")
    @ResponseBody
    public JSONObject  obtainAssessmentAlertData(String pensionNo,int maxSize){
        try {
            return statisticsDataService.queryUserAssessmentWarningDate(pensionNo,maxSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *
     * 功能描述：获取合同提醒信息
     *
     * @Author  GZ
     * @Date   2020/11/29 13:08
     */
    @RequestMapping("obtainContractAlertData")
    @ResponseBody
    public JSONObject  obtainContractAlertData(String pensionNo,int maxSize){
        try {
            return statisticsDataService.queryUserContractWarningDate(pensionNo,maxSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *
     * 功能描述：获取楼苑分布图信息
     *
     * @Author  GZ
     * @Date   2020/11/29 13:08
     */
    @RequestMapping("obtainBuildingInfoDetail")
    @ResponseBody
    public JSONObject  obtainBuildingInfoDetail(String buildingNo){
        try {
            return statisticsDataService.queryBuildingInfoData(buildingNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
    * 
    * 功能描述：养老机构基础统计数据设置
    *
    * @Author  GZ
    * @Date   2020/12/14 11:05
    */
    @RequestMapping("basicStaticDataSet")
    public String basicStaticDataSet(Model model){
        try {
            YlBasicData basicData = statisticsDataService.queryBasicDataInfo();
            model.addAttribute("basicData",basicData);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "/statistic/basicDataSet";
    }
    /**
    * 
    * 功能描述：保存基础统计设置信息
    *
    * @Author  GZ
    * @Date   2020/12/16 15:46
    */
    @RequestMapping("saveBasicStaticDataSet")
    @ResponseBody
    public JSONObject saveBasicStaticDataSet(YlBasicData basicData){
        try {
            return statisticsDataService.saveOrUpdateBasicDateInfo(basicData);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
